package cn.com.unionlife.hy.core.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {

	public static String getMD5Digest(String strInfo) {
		String strInfoDigest = "";
		try {
			MessageDigest messageDigest = MessageDigest.getInstance("MD5");
			messageDigest.update(strInfo.getBytes());
			byte bInfoDigest[] = messageDigest.digest();
			strInfoDigest = byteToHex(bInfoDigest);
		} catch (NoSuchAlgorithmException ex) {
			System.out.println("加密失败！");
		}
		return strInfoDigest;
	}
	
	public static String byteToHex(byte bInfoDigest[]) {
		String strInfoDigest = "";
		String strTemp = "";
		for (int i = 0; i < bInfoDigest.length; i++) {
			strTemp = Integer.toHexString(bInfoDigest[i] & 0xff);
			if (strTemp.length() == 1)
				strInfoDigest = strInfoDigest + "0" + strTemp;
			else
				strInfoDigest = strInfoDigest + strTemp;
		}
		strInfoDigest = strInfoDigest.toUpperCase();
		return strInfoDigest;
	}
	
}
